package paopao
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.utils.setTimeout;

	import utils.Ball;

	/**
	 * 打泡泡游戏
	 * @author sjp
	 *
	 */
	public class PaoPaoTest extends Sprite
	{
		private var pool:Paopaopool;
		private var shoot:Shoot;

		public function PaoPaoTest()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			setTimeout(init, 500);
		}

		private function init():void
		{
			pool = new Paopaopool();
			pool.rect = new Rectangle(10, 10, stage.stageWidth, stage.stageHeight / 2);
			addChild(pool);
			shoot = new Shoot();
			shoot.rect = new Rectangle(10, 10, stage.stageWidth, stage.stageHeight);
			addChild(shoot);
			this.addEventListener(Event.ENTER_FRAME, enterFrameHandler)
		}

		private function enterFrameHandler(event:Event):void
		{
			pool.enterFrameHandler(event);
			shoot.enterFrameHandler(event);
			if (shoot.isShooted)
			{
				var ball:Ball = pool.getTouchBall(shoot.shootBall);
				if (ball)
				{
					pool.destory(ball);
					shoot.reBorn();
				}
			}
		}
	}
}